package com.colorlight.cloud.xm.entity.instructions;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.xm.api.XmEntityScheduleActions;
import com.colorlight.iot.proto.xm.instruction.XmInstruction;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author Demon
 * @description 解密指令
 * @date 22/3/2024  上午8:59
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class RemoveDevice implements XmEntityScheduleActions {
	private InputMsg input;
	private OutputMsg output;
	
	@Override
	public ByteString objectConvertBytes() {
		XmInstruction.RemoveDevice.InputMsg.Builder inputMsg =
				XmInstruction.RemoveDevice.InputMsg.newBuilder();
		XmInstruction.RemoveDevice.Builder removeDevice =
				XmInstruction.RemoveDevice.newBuilder();
		removeDevice.setInput(inputMsg);
		return removeDevice.build().toByteString();
	}
	
	@Override
	public RemoveDevice byteConvertObject(ByteString bytes) {
		XmInstruction.RemoveDevice removeDevice = null;
		try {
			removeDevice = XmInstruction.RemoveDevice.parseFrom(bytes);
		} catch (InvalidProtocolBufferException e) {
			log.error("", e);
		}
		if (Objects.isNull(removeDevice)) {
			throw new ParameterException(ExceptionEnum.MSG_PARAMETER_EXCEPTION);
		}
		final OutputMsg outputMsg = new OutputMsg();
		this.setOutput(outputMsg);
		return this;
	}
	

	
	@Data
	@NoArgsConstructor
	@Builder
	public static class InputMsg implements Serializable {
	}
	
	@Data
	@NoArgsConstructor
	@Builder
	public static class OutputMsg implements Serializable {
	}
	
}
